home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Pascal
/
Book Demos in Pascal
/
TextGrid
/
TextGrid.p
< prev
next >
Wrap
Text File
|
1995-05-26
|
3KB
|
120 lines
program TextGrid;
{$IFC UNDEFINED THINK_PASCAL}
uses
Types, QuickDraw, Fonts, Events, Packages, Menus, Dialogs, Windows,{}
OSUtils, ToolUtils, OSEvents, Resources;
{$ENDC}
const
(*Size of the array*)
kArraySizeH = 15;
kArraySizeV = 12;
(*Size of the tiles*)
kTileSizeH = 32;
kTileSizeV = 32;
var
(*The world is accessed through a Handle to a 'TEXT' resource:*)
gWorldHandle: Handle; {Not a "GWorld", but a Global Handle to the world!}
const
(*…and this is the resource number:*)
kWorldResource = 128;
var
(* Pictures*)
floorTile: PicHandle;
playerTile: PicHandle;
enemyTile: PicHandle;
goldTile: PicHandle;
wallTile: PicHandle;
exitTile: PicHandle;
(* Draw a tile *)
procedure DrawTile (h: Integer; v: Integer);
var
tileRectangle: Rect;
theTile: char;
begin
SetRect(tileRectangle, h * kTileSizeH, v * kTileSizeV, (h + 1) * kTileSizeH, (v + 1) * kTileSizeV);
theTile := Char(Ptr(Longint(gWorldHandle^) + h + v * (kArraySizeH + 1))^);
case theTile of
' ':
DrawPicture(floorTile, tileRectangle);
'#':
DrawPicture(wallTile, tileRectangle);
'@':
DrawPicture(playerTile, tileRectangle);
'*':
DrawPicture(enemyTile, tileRectangle);
'$':
DrawPicture(goldTile, tileRectangle);
'X':
DrawPicture(exitTile, tileRectangle);
otherwise
PaintRect(tileRectangle);
end; {case}
end; (*DrawTile*)
(* Standard inits *)
procedure InitToolbox;
begin
{$IFC UNDEFINED THINK_PASCAL}
InitGraf(@qd.thePort);
InitFonts;
FlushEvents(everyEvent, 0);
InitWindows;
InitMenus;
TEInit;
InitDialogs(nil);
{$ENDC}
InitCursor;
end;
(****************** Main program ******************)
var
myWindow: WindowPtr;
windowRectangle: Rect;
h, v: Integer;
begin
InitToolbox;
(*Set up the window*)
SetRect(windowRectangle, 50, 50, 50 + kArraySizeH * kTileSizeH, 50 + kArraySizeV * kTileSizeV);
myWindow := NewCWindow(nil, windowRectangle, 'Text grid demo', true, 0, WindowPtr(-1), false, 0);
SetPort(myWindow);
(*Load all pictures*)
floorTile := GetPicture(128); (*PICT resource #128.*)
playerTile := GetPicture(129); (*PICT resource #129.*)
enemyTile := GetPicture(130); (*PICT resource #130.*)
goldTile := GetPicture(131); (*PICT resource #131.*)
wallTile := GetPicture(132); (*PICT resource #132.*)
exitTile := GetPicture(133); (*PICT resource #133.*)
(*Get the resource*)
gWorldHandle := GetResource('TEXT', kWorldResource);
if (gWorldHandle = nil) then (*Error! In a real program, you should check the picts above as well.*)
begin
SysBeep(1);
ExitToShell;
end;
(*Draw all tiles!*)
for h := 0 to kArraySizeH - 1 do
for v := 0 to kArraySizeV - 1 do
DrawTile(h, v);
while not Button do
;
end. (*TextGrid*)